package com.xiaoyang.ssyx.product.service.impl;

import com.xiaoyang.ssyx.product.service.FileUploadService;
import com.xiaoyang.ssyx.product.utils.MinioUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @AUTHOR XiaoYang
 * @DATE 2023/6/16-12:18
 * @DESCRIPTION TODO
 */
@Service
public class FileUploadServiceImpl implements FileUploadService {

    @Autowired
    private MinioUtil minioUtil;
    @Value("${minio.bucket}")
    private String bucketName;

    //图片上传
    @Override
    public String uploadFile(MultipartFile file) {
        List<String> names = minioUtil.upload(new MultipartFile[]{file}, bucketName);
        return minioUtil.getUri(names.get(0));
    }
}
